#!/bin/bash

# 定义需要重新安装的Planning相关包列表
PACKAGES=(
    "planning-base"
    "planning-interface-base"
    "planning-open-space"
    "planning-planner-public-road"
    "planning-lane-follow-map"
    "planning"
    "planning-task-piecewise-jerk-speed"
    "planning-task-rule-based-stop-decider"
    "planning-task-open-space-trajectory-partition"
    "planning-task-piecewise-jerk-speed-nonlinear"
    "planning-task-path-reference-decider"
    "planning-task-lane-borrow-path"
    "planning-task-path-decider"
    "planning-task-speed-bounds-decider"
    "planning-task-path-time-heuristic"
    "planning-task-open-space-fallback-decider"
    "planning-task-st-bounds-decider"
    "planning-task-pull-over-path"
    "planning-task-reuse-path"
    "planning-task-open-space-pre-stop-decider"
    "planning-task-open-space-trajectory-provider"
    "planning-task-fallback-path"
    "planning-task-lane-change-path"
    "planning-task-lane-follow-path"
    "planning-task-speed-decider"
    "planning-task-open-space-roi-decider"
    "planning-task-rss-decider"
    "planning-task-fast-stop-trajectory-fallback"
    "planning-traffic-rules-yield-sign"
    "planning-traffic-rules-keepclear"
    "planning-traffic-rules-rerouting"
    "planning-traffic-rules-backside-vehicle"
    "planning-traffic-rules-traffic-light"
    "planning-traffic-rules-reference-line-end"
    "planning-traffic-rules-crosswalk"
    "planning-traffic-rules-stop-sign"
    "planning-traffic-rules-destination"
    "planning-scenario-yield-sign"
    "planning-scenario-valet-parking"
    "planning-scenario-park-and-go"
    "planning-scenario-traffic-light-protected"
    "planning-scenario-emergency-pull-over"
    "planning-scenario-lane-follow"
    "planning-scenario-traffic-light-unprotected-left-turn"
    "planning-scenario-pull-over"
    "planning-scenario-bare-intersection-unprotected"
    "planning-scenario-emergency-stop"
    "planning-scenario-traffic-light-unprotected-right-turn"
    "planning-scenario-stop-sign-unprotected"
)

# 显示将要处理的包数量
echo "准备重新安装 ${#PACKAGES[@]} 个Planning相关包..."
echo "----------------------------------------"

# 遍历包列表并执行重新安装命令
for package in "${PACKAGES[@]}"; do
    echo "正在重新安装: $package"
    buildtool reinstall "$package"
    
    # 检查命令执行结果
    if [ $? -eq 0 ]; then
        echo "成功重新安装: $package"
    else
        echo "Error: 重新安装 $package 失败!"
        # 询问是否继续或中止
        read -p "是否继续处理其他包? (y/n) " -n 1 -r
        echo
        if [[ ! $REPLY =~ ^[Yy]$ ]]; then
            echo "用户中止操作"
            exit 1
        fi
    fi
    echo "----------------------------------------"
done

echo "所有包处理完毕"
